<?php
/**
* 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Datagram
 * @subpackage G
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: Aggregate.php 7 2009-11-14 22:42:08Z nkeyes $
 */


/**
 * 
 * @author Nathan Keyes
 *
 */
class Bushido_Datagram_Aggregate extends Bushido_Datagram_Abstract
{
	/**
	 * The name of this chart
	 * 
	 * @var string
	 */	protected $chartDisplayName ='';
	protected $charts = array();
	
	
	/**
	 * 
	 * @param $charts
	 * @param $configOptions
	 * @return void
	 */
	public function __construct($charts, $configOptions = array())
	{
		parent::__construct($configOptions);

		$this->allowedConfigOptions = array('id', 'caption');
		$this->config = new Bushido_Configurable();
		$this->config->addAllowedConfigOptions($this->allowedConfigOptions);
		$this->config->setConfigOptions($configOptions);
		
		if(!is_array($charts) && !is_subclass_of($charts, 'Bushido_Datagram_Abstract'))
		{
			throw new Exception('the first parameter passed to Bushido_Datagram_Aggregate::__construct() must be an array or an instance of Bushido_Datagram_Abstract');
		}
		elseif(is_array($charts))
		{
			foreach($charts as $chart)
			{
				if(!is_subclass_of($chart, 'Bushido_Datagram_Abstract'))
				{
					throw new Exception('each element of the first array passed to Bushido_Datagram_Aggregate::__construct() must be an instance of Bushido_Datagram_Abstract');
				}
				else
				{
					$this->charts[] = $chart;
				}
			}
			unset($chart);
		}
		else
		{
			$this->charts[] = $charts;
		}
	}

	
	/**
	 * 
	 * @return string The name of this chart
	 */
	public function getChartDisplayName()
	{
		return $this->chartDisplayName;
	}
	
	/**
	 * Sets the raw data for this chart
	 * @return void
	 */
	protected function _setRawData()
	{
		$this->rawData = array();
		
		foreach($this->charts as $chart)
		{
			$this->rawData = array_merge($this->rawData, $chart->getRawData());
			
		}
		unset($chart);
		//var_dump($this->rawData);exit(0);
	}
}